package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Rest风格开发
 * @author lixu
 */
@Controller
@RequestMapping("/rest")
public class RestController {

    /**
     * 添加
     *  Get
     *  http://localhost:8080/user?id=123&name=小小龙
     *  Rest风格
     *  http://localhost:8080/user/123/小小龙
     *
     *  请求体中
     *    结论： Post请求 请求体中的文本格式是中文乱码
     */
    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public void addUser(User user){
        System.out.println("name:" + user.getName());
    }
    /**
     * 修改
     *
     */
    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public @ResponseBody User updateUser(@RequestBody User user){

        System.out.println(user);


        return user;
    }
    /**
     * 删除
     *
     */
    @RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE)
    public @ResponseBody String deleteUser(@PathVariable Integer id){
        System.out.println("deleteUser:id:" + id);
        //SQL 将Mysql数据库的数据删除了

        // {status:1} : 响应的是JSON串  响应头上 application/json
        // OK   ： 响应的是    text/plain
        return "OK";
    }
    /**
     * 查询
     *
     */
    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    public void findUser(@PathVariable Integer id){
        System.out.println("RestController:findUser:id:" + id);
    }
}
